<!--
 *  Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree.
-->
<link rel="import" href="../../components/polymer/polymer.html">
<link rel="import" href="../../components/paper-button/paper-button.html">
<link rel="import" href="../../components/paper-input/paper-input.html">
<link rel="import" href="../../components/paper-input/paper-textarea.html">
<link rel="import" href="../../components/paper-dialog/paper-dialog.html">

<script src="../js/report.js"></script>

<dom-module name="report-dialog">
  <template>
    <!-- Report dialog -->
    <paper-dialog id="mainDialog" modal>
      <h2>Create a report</h2>
      <div>
        <paper-textarea id="textArea" label="Describe your issue here" value="{{description}}"></paper-textarea>
      </div>
      <h3>Note</h3>
      <p>The report will contain information about your device including network information 
        that is useful to troubleshoot the issue.</p>
      <p>You may want to share it with someone investigating your issue, or create a new
        issue in the <a href="//github.com/webrtc/testrtc/issues/new">testrtc</a> project.</p>
      <div class="buttons">
        <paper-button on-tap="download" disabled$="{{submitting}}">Download report</paper-button>
        <paper-button dialog-dismiss disabled$="{{submitting}}">Cancel</paper-button>
      </div>
    </paper-dialog>

  </template>
  <script>
    Polymer({
      is: 'report-dialog',
      open: function() {
        window.a = this.$.mainDialog;
        this.$.mainDialog.open();
      },

      download: function() {
        var fileContent = report.generate(this.description);
        var content = encodeURIComponent(fileContent);
        var link = document.createElement('a');
        link.setAttribute('href', 'data:text/plain;charset=utf-8,' + content);
        link.setAttribute('download', 'testrtc-' + (new Date().toJSON()) + '.log');
        link.click();
      },
    });
  </script>
</dom-module>
